home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk70 / magus110 / magus!cntl.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  14KB  |  550 lines

  1. /*-----------------------------Start Rexx Source------------------------------*/
  2.  
  3.  
  4. /*    Magus!Cntl.rexx          Modified:  15-APR-89
  5.  
  6.     Magus! Print Spooler
  7.            v1.10               Associated files: Magus!.rexx
  8.                                                  Magus!Util.rexx
  9.             by                                   MPrint.rexx
  10.         Dan Schenck                              MPrintIt.rexx
  11.          Tulsa, OK
  12.  
  13.       GEnie: D.SCHENCK
  14.        (918) 492-0523
  15.                          */
  16.  
  17. /*  Requires rexxarplib.library v2.1 */
  18.  
  19.   true = 1
  20.   false = 0
  21.  
  22.   pm = false
  23.   time2save = false
  24.  
  25.   top    = " Top  "
  26.   bottom = "Bottom"
  27.   left   = " Left "
  28.   center = "Center"
  29.   right  = "Right "
  30.   page_on  = "Page Numbering ON "
  31.   page_off = "Page Numbering OFF"
  32.   px0 = 120
  33.   py0 =  71
  34.   px1 = px0 + 18
  35.   py1 = py0 + 14
  36.   px2 = px1 + 58
  37.   py2 = py1
  38.  
  39.   dx = 67
  40.   dy = 48
  41.   tx = dx + 75
  42.   ty = dy
  43.   fx = dx + 150
  44.   fy = dy
  45.   ds_on  = "Date ON "
  46.   ds_off = "Date OFF"
  47.   ts_on  = "Time ON "
  48.   ts_off = "Time OFF"
  49.   fs_on  = "File Name ON "
  50.   fs_off = "File Name OFF"
  51.  
  52.   config_file = Getenv('config_file')
  53.   copy_dir = Getenv('copy_dir')
  54.   file_separator = Getenv('file_separator')
  55.   d_raw_options = Getenv('prt_options_raw')
  56.   call GetOptions()
  57.  
  58.   sdhelp = "Enter Spooler Directory in gadget below\"
  59.   sdhelp = sdhelp || "or leave null to print files ""In Place""."
  60.  
  61.   cphelp = "Enter number of copies to be\printed in gadget below."
  62.  
  63.   lphelp = "Enter number of lines/page to\be printed in gadget below."
  64.  
  65.   fshelp = "Enter file separator string\in gadget below.\\Backslash ""n"" = NEWLINE\Backslash ""f"" = FORMFEED"
  66.  
  67.   call MenuWindow2(MCNTLHOST,MCNTLPORT)
  68.   call BuildControls()
  69.   call SetAPen(MCNTLHOST,1)
  70.   call SetOPen(MCNTLHOST,1)
  71.  
  72.   time2go = false
  73.   time2exit = false
  74.   all_ok = true
  75.   do until(time2exit) /*5*/
  76.     t = waitpkt(MCNTLPORT)
  77.     do i = 1 /*6*/
  78.       p = getpkt(MCNTLPORT)
  79.       if c2d(p) = 0 then leave i
  80.       command = getarg(p)
  81.       select /*7*/
  82.  
  83.         when command = "COPIES" then call Copies()
  84.  
  85.         when command = "COPIES#" then call Copies_No()
  86.  
  87.         when command = "PAGE0" then call Page0()
  88.  
  89.         when command = "PAGE1" then call Page1()
  90.  
  91.         when command = "PAGE2" then call Page2()
  92.             
  93.         when command = "LINESPP" then
  94.           do
  95.             t = reply(p,0)
  96.             call Request(100,100,lphelp,,"  OK  ")
  97.           end
  98.  
  99.         when command = "LPP#" then call LPP_No()
  100.  
  101.         when command = "DSTAMP" then call Dstamp()
  102.  
  103.         when command = "TSTAMP" then call Tstamp()
  104.  
  105.         when command = "FSTAMP" then call Fstamp()
  106.  
  107.         when command = "FILESEP" then
  108.           do
  109.             t = reply(p,0)
  110.             call Request(100,100,fshelp,,"  OK  ")
  111.           end
  112.  
  113.         when command = "FILESS" then call Filess()
  114.  
  115.         when command = "USESETTINGS" then call Usesettings()
  116.  
  117.         when command = "SPOOLDIR" then
  118.           do
  119.             call Request(100,100,sdhelp,,"  OK  ")
  120.           end
  121.  
  122.         when command = "SPOOLNAM" then call Spoolnam()
  123.  
  124.         when command = "ABORT" then
  125.           do
  126.             t = reply(p,0)
  127.             all_ok = false
  128.             time2exit = true
  129.           end
  130.  
  131.         when command = "LOADFILE" then call Loadfile()
  132.  
  133.         when command = "SAVEFILE" then call Savefile()
  134.  
  135.         otherwise
  136.           t = reply(p,0)
  137.           if time2go then time2exit = true
  138.  
  139.         end /*7*/
  140.       end /*6*/
  141.     end /*5*/
  142.  
  143. if all_ok then call SetOptions()
  144. if pm then call PostMsg()
  145. call CloseWindow(MCNTLHOST)
  146.  
  147. exit
  148.  
  149. Copies:
  150.   t = reply(p,0)
  151.   call Request(100,100,cphelp,,"  OK  ")
  152.   return
  153.  
  154. Copies_No:
  155.   do i = 1 to 1
  156.     text = getarg(p,1)
  157.     t = reply(p,0)
  158.     if verify(text,"0123456789") = 0 then
  159.       if text > 0 then
  160.         do
  161.           copies = text
  162.           leave i
  163.         end
  164.       call PostMsg(50,50,"WARNING!\\Number of Copies incorrect.")
  165.       call Delay(150)
  166.       call RemoveGadget(MCNTLHOST,"COPIES#")
  167.       call AddGadget(MCNTLHOST,  7, 54,"COPIES#",copies,"%d%1%g",52)
  168.       call PostMsg
  169.   end
  170.   return
  171.  
  172. Page0:
  173.   t = reply(p,0)
  174.   if page_no then
  175.     do
  176.       page_no = false
  177.       page0_stat = page_off
  178.       lpp = "null"
  179.       call RemoveGadget(MCNTLHOST,"LPP#")
  180.       call AddGadget(MCNTLHOST,  7, 83,"LPP#",lpp,"%d%1%g",84)
  181.     end
  182.   else
  183.     do
  184.       page_no = true
  185.       page0_stat = page_on
  186.       if lpp = "null" then
  187.         do
  188.           lpp = 84
  189.           call RemoveGadget(MCNTLHOST,"LPP#")
  190.           call AddGadget(MCNTLHOST,  7, 83,"LPP#",lpp,"%d%1%g",84)
  191.         end
  192.     end
  193.   call RemoveGadget(MCNTLHOST,"PAGE0")
  194.   call RectFill(MCNTLHOST,px0,py0,px0+170,py1-2)
  195.   call Addgadget(MCNTLHOST,px0,py0,"PAGE0",page0_stat,"%d")
  196.   return
  197.  
  198. Page1:
  199.   t = reply(p,0)
  200.   if page1_stat = top then
  201.     do
  202.       page1_stat = bottom
  203.       torb = "b"
  204.     end
  205.   else
  206.     do
  207.       page1_stat = top
  208.       torb = "t"
  209.     end
  210.   call RemoveGadget(MCNTLHOST,"PAGE1")
  211.   call RectFill(MCNTLHOST,px1,py1,px1+55,py1+12)
  212.   call AddGadget(MCNTLHOST,px1,py1,"PAGE1",page1_stat,"%d")
  213.   return
  214.  
  215. Page2:
  216.   t = reply(p,0)
  217.   if page2_stat = left then
  218.     do
  219.       page2_stat = center
  220.       lrc = "c"
  221.     end
  222.   else if page2_stat = center then
  223.     do
  224.       page2_stat = right
  225.       lrc = "r"
  226.     end
  227.   else
  228.     do
  229.       page2_stat = left
  230.       lrc = "l"
  231.     end
  232.   call RemoveGadget(MCNTLHOST,"PAGE2")
  233.   call RectFill(MCNTLHOST,px2,py2,px2+55,py2+12)
  234.   call AddGadget(MCNTLHOST,px2,py2,"PAGE2",page2_stat,"%d")
  235.   return
  236.  
  237. LPP_No:
  238.   do i = 1 to 1
  239.     text = getarg(p,1)
  240.     t = reply(p,0)
  241.     if verify(text,"0123456789") = 0 then
  242.       if text > 0 then
  243.         do
  244.           lpp = text
  245.           leave i
  246.         end
  247.       else nop
  248.     else if text = "null" then
  249.       do
  250.         lpp = text
  251.         leave i
  252.       end
  253.     call PostMsg(50,50,"WARNING!\\Lines/page incorrect.")
  254.     call Delay(150)
  255.     call RemoveGadget(MCNTLHOST,"LPP#")
  256.     call AddGadget(MCNTLHOST,  7, 83,"LPP#",lpp,"%d%1%g",84)
  257.     call PostMsg()
  258.   end
  259.   return
  260.  
  261. Dstamp:
  262.   t = reply(p,0)
  263.   if date_stat = ds_on then
  264.     do
  265.       date_stat = ds_off
  266.       date = "off"
  267.     end
  268.   else
  269.     do
  270.       date_stat = ds_on
  271.       date = "on"
  272.     end
  273.   call RemoveGadget(MCNTLHOST,"DSTAMP")
  274.   call RectFill(MCNTLHOST,dx,dy,dx+71,dy+12)
  275.   call AddGadget(MCNTLHOST, dx, dy,"DSTAMP",date_stat,"%d")
  276.   return
  277.  
  278. Tstamp:
  279.   t = reply(p,0)
  280.   if time_stat = ts_on then
  281.     do
  282.       time_stat = ts_off
  283.       time = "off"
  284.     end
  285.   else
  286.     do
  287.       time_stat = ts_on
  288.       time = "on"
  289.     end
  290.   call RemoveGadget(MCNTLHOST,"TSTAMP")
  291.   call RectFill(MCNTLHOST,tx,ty,tx+71,ty+12)
  292.   call AddGadget(MCNTLHOST, tx, ty,"TSTAMP",time_stat,"%d")
  293.   return
  294.  
  295. Fstamp:
  296.   t = reply(p,0)
  297.   if filename_stat = fs_on then
  298.     do
  299.       filename_stat = fs_off
  300.       filename = "off"
  301.     end
  302.   else
  303.     do
  304.       filename_stat = fs_on
  305.       filename = "on"
  306.     end
  307.   call RemoveGadget(MCNTLHOST,"FSTAMP")
  308.   call RectFill(MCNTLHOST,fx,fy,fx+110,fy+12)
  309.   call AddGadget(MCNTLHOST, fx, fy,"FSTAMP",filename_stat,"%d")
  310.   return
  311.  
  312. Filess:
  313.   file_separator = getarg(p,1)
  314.   t = reply(p,0)
  315.   call RemoveGadget(MCNTLHOST,"FILESS")
  316.   call AddGadget(MCNTLHOST,155, 26,"FILESS",file_separator,"%d%1%g",172)
  317.   if time2go then time2exit = true
  318.   if time2save then call ReadHost(MCNTLHOST,MCNTLPORT,"SAVEFILE")
  319.   return
  320.  
  321. Usesettings:
  322.   t = reply(p,0)
  323.   pm = true
  324.   call PostMsg(50,50,"  OK!  ")
  325.   time2go = true
  326.   call ReadGadget(MCNTLHOST,"SPOOLNAM")
  327.   call ReadGadget(MCNTLHOST,"COPIES#")
  328.   call ReadGadget(MCNTLHOST,"LPP#")
  329.   call ReadGadget(MCNTLHOST,"FILESS")
  330.   return
  331.  
  332. Spoolnam:
  333.   do i = 1 to 1
  334.     text = getarg(p,1)
  335.     t = reply(p,0)
  336.     if text = copy_dir then leave i
  337.     if (text = "" | text = "NULL" | text = "null") then copy_dir = "null"
  338.     else if (~exists(text) | left(statef(text),1) ~= 'D') then
  339.       do
  340.         call PostMsg(50,50,"! WARNING \\"||text||" is not appropriate.\\Please reenter.")
  341.         call delay(150)
  342.         call RemoveGadget(MCNTLHOST,"SPOOLNAM")
  343.         call AddGadget(MCNTLHOST,  7, 26,"SPOOLNAM",copy_dir,"%d%1%g",140)
  344.         call PostMsg()
  345.       end
  346.     else
  347.       do
  348.         last_char = right(text,1)
  349.         if last_char ~= ":" & last_char ~= "/" then text = text || "/"
  350.         copy_dir = text || "++M!Spool"
  351.         if ~exists(copy_dir) then address command "makedir" copy_dir
  352.       end
  353.   end
  354.   return
  355.  
  356. Loadfile:
  357.   t = reply(p,0)
  358.   do until(exists(c_file) | c_file = "")
  359.     c_file = GetFile(100,100,"S:*.config","MAGUS!.config","Select Config File")
  360.   end
  361.   if c_file ~= "" then
  362.     do
  363.       config_file_bak = config_file
  364.       config_file = c_file
  365.       call open('in',config_file,"Read")
  366.       if readln('in') ~= "MAGUS! config file" then
  367.         do
  368.           call close('in')
  369.           config_file = config_file_bak
  370.           call PostMsg(50,50,"WARNING!\\Bad config file """||config_file||""".\\Skipping ""LOAD"".")
  371.           call Delay(150)
  372.           call PostMsg()
  373.         end
  374.       else
  375.         do
  376.           copy_dir       = readln('in')
  377.           file_separator = readln('in')
  378.           d_raw_options  = readln('in')
  379.           call GetOptions()
  380.           call close('in')
  381.           call RemoveGs()
  382.           call BackFill(MCNTLHOST)
  383.           call BuildControls()
  384.         end
  385.     end
  386.   return
  387.  
  388. Savefile:
  389.   t = reply(p,0)
  390.   if ~time2save then
  391.     do
  392.       call PostMsg(50,50,"Saving Settings!")
  393.       call ReadGadget(MCNTLHOST,"SPOOLNAM")
  394.       call ReadGadget(MCNTLHOST,"COPIES#")
  395.       call ReadGadget(MCNTLHOST,"LPP#")
  396.       call ReadGadget(MCNTLHOST,"FILESS")
  397.       time2save = true
  398.     end
  399.   else
  400.     do
  401.       do until(exists(c_file) | c_file = "")
  402.         c_file = GetFile(100,100,"S:*.config","MAGUS!.config","Select Config File")
  403.       end
  404.       if c_file ~= "" then
  405.         do
  406.           config_file = c_file
  407.           call open('out',config_file,"Write")
  408.           call writeln('out',"MAGUS! config file")
  409.           call writeln('out',copy_dir)
  410.           call writeln('out',file_separator)
  411.           if page_no then page = torb || lrc
  412.           else page = "null"
  413.           call writeln('out',copies||" "||lpp||" "||page||" "||date||" "||time||" "filename)
  414.           call close('out')
  415.         end
  416.       time2save = false
  417.       call PostMsg()
  418.     end
  419.   return
  420.  
  421. /*  Setup the host and open window for Magus! control display  */
  422.  
  423.   MenuWindow2:
  424.   arg hostcntl, hostport
  425.  
  426.   chfile = "T:++Magus2.rexx"
  427.   if ~exists(chfile) then
  428.     do
  429.       call open('out',chfile,"Write")
  430.       call writeln('out',"/* Start Rexx Source */")
  431.       call writeln('out',"x = createhost(" || hostcntl || "," || hostport || ")")
  432.       call close('out')
  433.     end
  434.   address command arun "rx" chfile
  435.   mp = openport(hostport)
  436.   address command "c:WaitForPort" hostcntl
  437.   address command "c:WaitForPort" hostport
  438.   do until(showlist("P",hostcntl) & showlist("P",hostport))
  439.     call delay(10)
  440.   end
  441.   
  442.   idcmp = 'GADGETUP'
  443.   flags = 'WINDOWDRAG+WINDOWDEPTH+BACKFILL'
  444.  
  445.   call PostMsg()
  446.  
  447.   call OpenWindow(hostcntl,0,23,335,136,idcmp,flags,"Magus! Controls")
  448.  
  449.   return 0
  450.  
  451. /* Set print options environment variables */
  452.  
  453. SetOptions:
  454.   if page_no then page = torb || lrc
  455.   else page = "null"
  456.   d_raw_options = copies||" "||lpp||" "||page||" "||date||" "||time||" "filename
  457.   rtn = Setenv('copy_dir',copy_dir)
  458.   rtn = Setenv('file_separator',file_separator)
  459.   rtn = Setenv('prt_options_raw',d_raw_options)
  460.   rtn = Setenv('config_file',config_file)
  461.  
  462.   return
  463.  
  464. /* Parse print options */
  465.  
  466. GetOptions:
  467.   parse VAR d_raw_options copies " " lpp " " page " " date " " time " " filename
  468.   if page = "null" then
  469.     do
  470.       page_no = false
  471.       page0_stat = page_off
  472.       page1_stat = top
  473.       torb = "t"
  474.       page2_stat = right
  475.       lrc = "r"
  476.     end
  477.   else
  478.     do
  479.       torb = left(page,1)
  480.       lrc  = right(page,1)
  481.       page_no = true
  482.       page0_stat = page_on
  483.       if upper(torb) = "T" then page1_stat = top
  484.       else page1_stat = bottom
  485.       if upper(lrc) = "L" then page2_stat = left
  486.       else if upper(lrc) = "C" then page2_stat = center
  487.         else page2_stat = right
  488.     end
  489.   if date = "on" then date_stat = ds_on
  490.   else date_stat = ds_off
  491.   if time = "on" then time_stat = ts_on
  492.   else time_stat = ts_off
  493.   if filename = "on" then filename_stat = fs_on
  494.   else filename_stat = fs_off
  495.  
  496.   return
  497.  
  498. /* Build window control gadgets */
  499.  
  500. BuildControls:
  501.  
  502.   call AddGadget(MCNTLHOST,  7, 14,"SPOOLDIR","Spooler Directory","%d")
  503.   call AddGadget(MCNTLHOST,  7, 26,"SPOOLNAM",copy_dir,"%d%1%g",140)
  504.   call AddGadget(MCNTLHOST,155, 14,"FILESEP","File Separator String","%d")
  505.   call AddGadget(MCNTLHOST,155, 26,"FILESS",file_separator,"%d%1%g",172)
  506.   call AddGadget(MCNTLHOST,  7, 42,"COPIES","Copies","%d")
  507.   call AddGadget(MCNTLHOST,  7, 54,"COPIES#",copies,"%d%1%g",52)
  508.   call AddGadget(MCNTLHOST, dx, dy,"DSTAMP",date_stat,"%d")
  509.   call AddGadget(MCNTLHOST, tx, ty,"TSTAMP",time_stat,"%d")
  510.   call AddGadget(MCNTLHOST, fx, fy,"FSTAMP",filename_stat,"%d")
  511.   call AddGadget(MCNTLHOST,  7, 71,"LINESPP","Lines/Page","%d")
  512.   call AddGadget(MCNTLHOST,  7, 83,"LPP#",lpp,"%d%1%g",84)
  513.   call Addgadget(MCNTLHOST,px0,py0,"PAGE0",page0_stat,"%d")
  514.   call AddGadget(MCNTLHOST,px1,py1,"PAGE1",page1_stat,"%d")
  515.   call AddGadget(MCNTLHOST,px2,py2,"PAGE2",page2_stat,"%d")
  516.  
  517.   call AddGadget(MCNTLHOST, 10,120,"USESETTINGS","  USE   ","%d")
  518.   call AddGadget(MCNTLHOST, 89,120,"ABORT"," CANCEL ","%d")
  519.   call AddGadget(MCNTLHOST,168,120,"LOADFILE","  LOAD  ","%d")
  520.   call AddGadget(MCNTLHOST,247,120,"SAVEFILE","  SAVE  ","%d")
  521.  
  522.   return
  523.  
  524. /* Remove all gadgets */
  525. RemoveGs:
  526.  
  527.   call RemoveGadget(MCNTLHOST,"SPOOLDIR")
  528.   call RemoveGadget(MCNTLHOST,"SPOOLNAM")
  529.   call RemoveGadget(MCNTLHOST,"FILESEP")
  530.   call RemoveGadget(MCNTLHOST,"FILESS")
  531.   call RemoveGadget(MCNTLHOST,"COPIES")
  532.   call RemoveGadget(MCNTLHOST,"COPIES#")
  533.   call RemoveGadget(MCNTLHOST,"DSTAMP")
  534.   call RemoveGadget(MCNTLHOST,"TSTAMP")
  535.   call RemoveGadget(MCNTLHOST,"FSTAMP")
  536.   call RemoveGadget(MCNTLHOST,"LINESPP")
  537.   call RemoveGadget(MCNTLHOST,"LPP#")
  538.   call RemoveGadget(MCNTLHOST,"PAGE0")
  539.   call RemoveGadget(MCNTLHOST,"PAGE1")
  540.   call RemoveGadget(MCNTLHOST,"PAGE2")
  541.  
  542.   call RemoveGadget(MCNTLHOST,"USESETTINGS")
  543.   call RemoveGadget(MCNTLHOST,"ABORT")
  544.   call RemoveGadget(MCNTLHOST,"LOADFILE")
  545.   call RemoveGadget(MCNTLHOST,"SAVEFILE")
  546.  
  547.   return
  548.  
  549. /*-----------------------------End of Rexx Source-----------------------------*/
  550.